﻿// Study0805.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第八章 多态 虚函数 虚析构函数

#include <iostream>
using namespace std;

class Base
{
public:
	~Base();
};

Base::~Base()
{
	cout << "调用Base类的析构函数" << endl;
}
class Derived final :public Base
{
public:
	Derived() {
		p = new int(0);
	}

	~Derived();
private:
	int* p;
};
Derived::~Derived()
{
	cout << "调用Derived类的析构函数" << endl;
	delete p;
}
void fun(Base* b)
{
	delete b;
}
int main()
{
	Base* b = new Derived();
	fun(b);
	return 0;
}


